/*
 * XErrorDialogTest.java
 * 
 * Copyright (c) 2006 - 2007
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.xfc.dialog;

import java.io.IOException;

import javax.swing.JDialog;

import org.xfc.testing.XMockApp;
import org.xfc.testing.XUITestCase;

public class XErrorDialogTest
	extends XUITestCase
{
	
	public XErrorDialogTest()
	{
		
	}
	
	protected void setUp()
	{
		XMockApp.init();
	}
	
	protected void tearDown()
	{
		XMockApp.dispose();
	}
	
	public void testShowErrorThrowable()
	{
		new Thread(new Runnable() {
			public void run() {
				XErrorDialog.showError(new IOException("error reading file bob.txt"));
			}
		}).start();
		
		waitFor(locateShowing("IOException"));
		
		JDialog dialog = findDialog("IOException");
		
		assertThat(dialog, not(eq(null)));
		assertThat(dialog, hasProperty("showing", eq(true)));
		assertThat(dialog, hasProperty("title"));
		
		dismissDialog(dialog);
	}
	
	public void testShowErrorStringString()
	{
		new Thread(new Runnable() {
			public void run() {
				XErrorDialog.showError("Test Error", "test test test");
			}
		}).start();
		
		waitFor(locateShowing("Test Error"));
		
		JDialog dialog = findDialog("Test Error");
		
		assertThat(dialog, not(eq(null)));
		assertThat(dialog, isComponentShowing());
		assertThat(dialog, hasProperty("title", eq("Test Error")));
		
		dismissDialog(dialog);
	}
	
	public void testShowWarningStringString()
	{
		final String title = "Test Warning";
		
		new Thread(new Runnable() {
			public void run() {
				XErrorDialog.showWarning(title, "test test test");
			}
		}).start();
		
		waitFor(locateShowing(title));
		
		JDialog dialog = findDialog(title);
		
		assertThat(dialog, not(eq(null)));
		assertThat(dialog, hasProperty("showing", eq(true)));
		assertThat(dialog, hasProperty("title", eq(title)));
		
		dismissDialog(dialog);
	}
	
}
